#!/usr/bin/env python
# encoding: utf-8
# @Time    : 2020/8/24 18:40
# @Author  : liuwenfan
# @File    : views.py
# @Software: PyCharm
# report

from . import report
from ...apps.report.service import report_service
from ...libs import const
from ...libs.framework import *


@report.route("/upper_part")
def upper_part():
    """
    仪表盘数据：健康程度饼图&用例数饼图&BUG排名柱状图&CASE数量柱状图
    :return:json
    """
    # 健康程度
    health = report_service.healthy()
    # CASE 数量
    project_total_case = report_service.casenum()
    # bug排名
    bug_number = report_service.bugnum()
    # 用例数
    implement = report_service.implementcase()
    data = {
        const.HEALTHY: health,
        const.BUG_SORT: bug_number,
        const.IMPLEMENT: implement,
        const.TOTAL_CASE: project_total_case
    }
    return result(const.SUCCESS, None, data)


@report.route("/lower_part")
def lower_build():
    """
    仪表盘数据：构建统计
    :return:json
    """
    data = report_service.build_count()
    return result(const.SUCCESS, None, data)


@report.route("/new_report")
def new_report():
    """
    仪表盘数据：构建记录
    :return:
    """
    data = report_service.report_record()
    return result(const.SUCCESS, None, data)


@report.route('/')
def index():
    return "this is report index"


@report.route('/aggregate_page/<task_id>/<BUILD_ID>')
def aggregate_page(task_id, BUILD_ID):
    """
    集成测试报告
    :param task_id: 任务id
    :param BUILD_ID: BUILD_ID
    :return: json
    """
    data = report_service.get_report_data(task_id, BUILD_ID)
    return result(const.SUCCESS, None, data)
